﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JKF.DataModule.SqlServerDAL;
using System.Data;
using JKF.Substructure;
using JKF.Entities.Model;

namespace JKF.BusinessLayer.BLL
{
    public partial class bllPRODUCT_SORT
    {
        /// <summary>
        /// 获取产品类别列表
        /// </summary>
        /// <param name="NAME">产品类别名称</param>
        /// <param name="pageCurrent">当前页码</param>
        /// <param name="pageSize">一页显示多少</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="rowCount">总记录数</param>
        /// <returns>返回DataTable数据</returns>
        public  DataTable GetProduct_SortsBLL(string NAME, int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            return dalPRODUCT_SORT.GetProduct_SortsDAL(NAME, pageCurrent, pageSize, ref pageCount, ref rowCount);
        }
        /// <summary>
       /// 判断产品分类名称是否存在
       /// </summary>
       /// <param name="product_sort_name"></param>
       /// <returns></returns>
        public  bool ExistsProduct_SortNameBLL(string product_sort_name)
        {
            return dalPRODUCT_SORT.ExistsProduct_SortNameDAL(product_sort_name);
        }
         /// <summary>
       /// 事务删除产品分类
       /// </summary>
       /// <param name="shop_code">产品分类ID</param>
       /// <returns></returns>
        public  string TransactionSQLDeleteBLL(Guid sort_key)
        {
            return dalPRODUCT_SORT.TransactionSQLDeleteDAL(sort_key);
        }
        /// <summary>
        /// 根据当前TYPE获取Select列表
        /// </summary>
        /// <returns></returns>
        public string GetProduct_SortByTypeBLL(string typeId)
        {
            //const string cacheName = "Product_SortOne"; 
            //if (!CacheManage.HadCache(cacheName))
            //{ 
                List<PRODUCT_SORTinfo> oList;
                oList = this.GetModelList(string.Format("TYPE='{0}'", typeId));
                var sb = new StringBuilder();
                if (oList.Count == 0)
                {
                    sb.AppendFormat("<option value=\"{0}\">{1}</option>", "-1", "无分类,请先录入！");
                    //CacheManage.AddCache(cacheName, sb.ToString());
                    //return CacheManage.GetCache(cacheName).ToString();
                    return sb.ToString();
                }
                foreach (var item in oList)
                {
                    sb.AppendFormat("<option value=\"{0}\">{1}</option>", item.SORT_KEY, item.NAME);
                }
                //CacheManage.AddCache(cacheName, sb.ToString());
            //}
            return sb.Insert(0, string.Format("<option value=\"{0}\">{1}</option>", "-1", "请选择")).ToString();
            //return CacheManage.GetCache(cacheName).ToString();
        }
        /// <summary>
        /// 产品入库/出库时，获取产品类别Select列表数据
        /// </summary>
        /// <returns></returns>
        public string GetProduct_Sort()
        {
            const string cacheName = "Product_SortOne";
            if (!CacheManage.HadCache(cacheName))
            {
                 
                List<PRODUCT_SORTinfo> oList = dal.GetListArray("");
                var sb = new StringBuilder();
                if (oList.Count == 0)
                {
                    sb.AppendFormat("<option value=\"{0}\" >{1}</option>", "-1", "无产品类别,请先录入！");
                    //CacheManage.AddCache(cacheName, sb.ToString());
                    //return CacheManage.GetCache(cacheName).ToString();
                    return sb.ToString();
                }
                foreach (var item in oList)
                {
                    sb.AppendFormat("<option value=\"{0}\" >{1}</option>", item.SORT_KEY+"|"+item.TYPE, item.NAME);
                }
                CacheManage.AddCache(cacheName, sb.ToString());
                 
            }
            return CacheManage.GetCache(cacheName).ToString();
        }
    }
}
